package com.linearList;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * @Author: linKe
 * @Date: 2021/12/30 16:49
 * @FileName: DoubleLinkedListTest
 * @version: 1.0
 * @Description: 双向链表数据结构测试类
 */
public class DoubleLinkedListTest {

    private DoubleLinkedList<Integer> list;

    @Before
    public void before(){
        Integer[] arr = {1,3,5,7,9};
        list = new DoubleLinkedList<>(arr);

    }

    @Test
    public void init() {
        //这个测试没有什么用 不需要init再初始化
    }

    @Test
    public void get() {
        //第一次测试的时候第一个数据被忽略了
        Integer integer = list.get(2);
        System.out.println(integer);
        System.out.println(list.get(1));
        System.out.println(list.get(3));
        System.out.println(list.get(4));
        System.out.println(list.get(5));
        /*3
            1
            5
            7
            9*/
    }

    @Test
    public void remove() {
        Integer remove = list.remove(2);
        System.out.println(remove);
        // 3
        Integer remove1 = list.remove(3);
        System.out.println(remove1);
        // 5 这里 数据并没有发生移位，删除没有生效
        // 7 修改删除逻辑后的值 正常序号后移的结果
    }

    @Test
    public void set() {
        list.set(2,4);
        Integer integer = list.get(2);
        System.out.println(integer);
        //  4
    }

    @Test
    public void search() {
        DoubleNode<Integer> search = list.search(3);
        System.out.println(search.getData());
        // 3
        DoubleNode<Integer> search1 = list.search(5);
        System.out.println(search1.getData());
        // 5
    }

    @Test
    public void insert() {
        DoubleNode<Integer> insert = list.insert(2, 2222);
        System.out.println(insert.getData());
        // 2222
        System.out.println(list.size());
        // 6
        System.out.println(list.get(2));
        System.out.println(list.get(3));
        /*
        * 3
          2222  数据确实添加在了结点序号2的 后面
        * */
    }

    @Test
    public void size() {
        int size = list.size();
        System.out.println(size);
        // 5
    }

    @Test
    public void testEquals() {
        Integer [] arr1 = {2,1};
        DoubleLinkedList<Integer> list1 = new DoubleLinkedList<>(arr1);
        boolean equals1 = list1.equals(list);
        System.out.println(equals1);
        // true 第一次返回结果为true 与实际不符
        // 修改最后返回判断的逻辑后 为false
        Integer [] arr2 = {1,3,5,7,9};
        DoubleLinkedList<Integer> list2 = new DoubleLinkedList<>(arr2);
        boolean equals2 = list2.equals(list);
        System.out.println(equals2);
        //  true 测试通过
    }
}